package com.permission.controller;

import com.solution.framework.controller.BaseController;
import com.solution.framework.model.BaseBean;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: sunguangzhu
 * Date: 14-5-13
 * Time: 上午10:20
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class IndexController extends BaseController<BaseBean> {
    @RequestMapping
    public String index(Model model, HttpServletRequest request, HttpServletResponse response) {
        System.out.println("index method ....");
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {
            String username = ((UserDetails) principal).getUsername();
            System.out.println("username = " + username);
        } else {
            String username = principal.toString();
            System.out.println("username = " + username);
        }
        return "index";
    }
}
